package com.dididoctor.patient.Activity.Usercentre.Consume;

import android.content.Context;
import android.view.View;
import android.widget.TextView;

import com.dididoctor.patient.MV.adapter.CommonAdapter;
import com.dididoctor.patient.MV.adapter.ViewHolder;
import com.dididoctor.patient.R;

import java.util.List;

/**
 * Created by Administrator on 2016/4/8.
 */
public class UserConsumeAdapter extends CommonAdapter<Consume> {

    private TextView mTvName, mTvMoney, mTvTime, mTvStatus, mTvRefund;
    private Paybacklistenct paybacklistenct;

    public UserConsumeAdapter(Context context, List<Consume> datas, Paybacklistenct paybacklistenct) {
        super(context, datas, R.layout.item_user_consume);
        this.paybacklistenct = paybacklistenct;
    }

    @Override
    public void convert(int position, ViewHolder helper, final Consume item) {
        mTvMoney = helper.getView(R.id.tv_money);
        mTvMoney.setText("支付金额:￥" + item.getMoney());
        mTvName = helper.getView(R.id.tv_name);
        mTvName.setText(item.getName());
        mTvTime = helper.getView(R.id.tv_time);
        mTvTime.setText("支付时间：" + item.getPayTime());
        mTvStatus = helper.getView(R.id.tv_status);
        mTvRefund = helper.getView(R.id.tv_refund);
        if ("3".equals(item.getStatus())) {
            mTvStatus.setText("已结束");
            mTvStatus.setVisibility(View.VISIBLE);
            mTvRefund.setVisibility(View.GONE);
        } else if ("4".equals(item.getStatus())) {
            mTvStatus.setText("已过期");
            mTvRefund.setVisibility(View.VISIBLE);
            mTvStatus.setVisibility(View.VISIBLE);
        } else if ("5".equals(item.getStatus())) {
            mTvStatus.setText("已退款");
            mTvRefund.setVisibility(View.GONE);
            mTvStatus.setVisibility(View.VISIBLE);
        } else {
            mTvStatus.setText("未结束");
            mTvRefund.setVisibility(View.GONE);
            mTvStatus.setVisibility(View.GONE);
        }

        mTvRefund.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                paybacklistenct.payback(item);
            }
        });

        helper.getConvertView().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        });

    }

    interface Paybacklistenct {
        void payback(Consume consume);
    }
}
